<template>
    <div>
        <el-menu active-text-color="#ffd04b" background-color="#545c64" class="el-menu-vertical-demo" :default-active="route.path"
            router text-color="#fff" @open="handleOpen" @close="handleClose">
            <el-menu-item index="/home">
                <el-icon><icon-menu /></el-icon>
                <span>首页</span>
            </el-menu-item>
            <el-sub-menu index="1" v-for="item in leftlistroute">
                <template #title>
                    <el-icon>
                        <location />
                    </el-icon>
                    <span>{{ item.meta.title }}</span>
                </template>
                <el-menu-item :index="item1.path" v-for="item1 in item.children">{{ item1.meta.title }}</el-menu-item>
            </el-sub-menu>
        </el-menu>
    </div>
</template>

<script setup lang="ts">
import {
    Document,
    Menu as IconMenu,
    Location,
    Setting,
} from '@element-plus/icons-vue'
import { ref } from 'vue'
import { useRouter, useRoute } from 'vue-router'
const router = useRouter()
const route = useRoute()
let leftlistroute = ref([])
router.getRoutes().forEach(item => {
    if (item.children.length != 0) {
        leftlistroute.value.push(item)
    }
})

const handleOpen = (key: string, keyPath: string[]) => {
    console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
    console.log(key, keyPath)
}
</script>

<style scoped></style>